__author__ = 'Kerr Wang'

import struct
import time
import json
import asyncio
import http.client
import urllib
import requests
import logging

OBJ_HOST = "hdu.sunnysport.org.cn"
OBJ_URL = "/remotestation/message"

def httpSend(host, url, port, data_str):
#	conn = http.client.HTTPConnection(host, port)
	conn = http.client.HTTPConnection(host, port, timeout = 5)
#	headers = {"Content-type":"application/json"}

	data = {'data':data_str}
#	print (data)
	headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "*/*"}
	params = urllib.parse.urlencode(data)
	conn.request("POST", url, params, headers)

	response = conn.getresponse()
	data = response.read()
	conn.close()
	return data

def main():
	file_name = input("输入文件名：")
	fp = open(file_name, "r")
	line = fp.readline()
	while line:
		result = httpSend(OBJ_HOST, OBJ_URL, 80, line)
		line = fp.readline()
		print (result)
	print ("complete")
	
if __name__ == '__main__':
	main()






